# cmd> regsvr32.exe miceshot.dll
import os, msvcrt, sys
import win32com.client
from tempfile import TemporaryFile 

def float_name(afolder):
    thempfile = "abracadabra"
    with TemporaryFile("wb", suffix=".bmp", dir = afolder) as thefile: thempfile = thefile.name
    return os.path.join( afolder, thempfile )
    
thefolder = sys.argv[1] if len(sys.argv) > 1 else r"."

theobj = win32com.client.Dispatch("oleauto.screenshot")
    # theobj.cursor = False
print "{ cursor: %s, width: %d, height: %d }" % (theobj.cursor, theobj.width, theobj.height)

theobj.pixelBits = 24
thempfile = float_name(thefolder)
print("miceshot, path name: %s" % thempfile)
#   with open(thempfile, mode='+wb') as thefile: 
thefile = os.open( thempfile, os.O_WRONLY | os.O_BINARY | os.O_CREAT )
try:
    theobj.load(msvcrt.get_osfhandle(thefile))
finally:
    os.close( thefile )

theobj.cursor, theobj.pixelBits = False, 16
thempfile = float_name(thefolder)
print("screenshot, path name: %s" % thempfile)
#   with open(thempfile, mode='+wb') as thefile: 
thefile = os.open( thempfile, os.O_WRONLY | os.O_BINARY | os.O_CREAT )
try:
    thereply = theobj.load(msvcrt.get_osfhandle(thefile), True)
finally:
    os.close( thefile )
#   if thereply then it is really fullscreen
theobj.pixelBits = 0 # resets to screen resolution
print "Bits per Pixel (32, 24, 16): ", theobj.pixelBits

print "have finished, status: ", theobj.length
#   theobj.load( 10, 0 )

#   theobj.load(r"g:\temp\python.bmp", True)
